import { LoginOutlined } from '@ant-design/icons';
import { Layout, Menu,message } from 'antd';
import React, { useEffect, useState } from 'react';
import { Outlet, useNavigate } from 'react-router-dom';
import { get } from '../../util/get';
import {post} from '../../util/post';
const { Header, Content, Footer, Sider } = Layout;

const Store = () =>{ 
  const navigate =useNavigate()
  const items = [
    {
      key:1,
      label:'首页',
      onClick:()=>{
        navigate('/home',{replace:true})
      }
    },{
      key:2,
            icon:<LoginOutlined />,
            onClick:()=>{
                post('/auth/logout').then(res=>{
                    if(res.data.code===0)
                    {
                        message.success('已登出')
                        navigate('/login')
                        localStorage.removeItem('TOKEN')
                        localStorage.removeItem('uid')
                    }
                    else
                    message.error(res.data.errorMsg)
                })
            }
    }
  ]
  const sideMenu = [{
    key: 1,
    label: '店铺管理',
    onClick:()=>{
      navigate('/store/manage',{replace:true})
    }
  },
  {
    key:3,
    label:'入驻申请',
    onClick:()=>{
      navigate('/store/apply',{replace:true})
    }
  }
]
  return(
  <Layout>
    <Header className="header">
      <div className="logo" />
      <Menu theme="dark" mode="horizontal" defaultSelectedKeys={['2']} items={items} />
    </Header>
    <Content
      style={{
        padding: '0 50px',
      }}
    >
      <Layout
        className="site-layout-background"
        style={{
          padding: '24px 0',
        }}
      >
        <Sider className="site-layout-background" width={200}>
          <Menu
            mode="inline"
            defaultSelectedKeys={['1']}
            defaultOpenKeys={['sub1']}
            style={{
              height: '100%',
            }}
            items={sideMenu}
          />
        </Sider>
        <Content
          style={{
            padding: '0 24px',
            minHeight: 570,
            background:'white'
          }}
        >
          <Outlet/>
        </Content>
      </Layout>
    </Content>
    <Footer
      style={{
        textAlign: 'center',
      }}
    >
      Ant Design ©2018 Created by Ant UED
    </Footer>
  </Layout>
)};

export default Store;